#ifndef PDFREADER_H
#define PDFREADER_H

#include <FileReader/BaseReader.h>

#include <poppler/poppler-config.h>
#include <poppler/GlobalParams.h>
#include <poppler/goo/GooString.h>
#include <poppler/PDFDoc.h>
#include <poppler/Page.h>
#include <poppler/Stream.h>
#include <poppler/TextOutputDev.h>

#include <iostream>

using std::cout;
using std::endl;

void __out(void *stream, char *text, int len) {
    *(static_cast <string *> (stream)) += text;
    //cout << text << endl;
};

class PDFReader: public BaseReader {
public:
    PDFReader() {}

    virtual string getContent(const char *filename) {
        PDFDoc        *_document;
        GooString     *_filename;
        TextOutputDev *_text_out;
        string         _content;

        globalParams = new GlobalParams();

        _filename = new GooString(filename);

        _document = new PDFDoc(_filename, NULL, NULL);
        _text_out = new TextOutputDev(__out, &_content, true, false);
        if (_text_out->isOk() && _document->isOk())
            _document->displayPages(
                _text_out, 1, _document->getNumPages(),
                72.0, 72.0, 1, true, false, false
            );


        delete _filename;
        //delete _document;
        delete globalParams;

        return _content;
    }
};

#endif // PDFREADER_H
